package org.example;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/21
 * Time: 22:15
 */
//设置访问路径(url)
@WebServlet("/method")
//继承HttpServlet并重写doGet和doPost方法
public class MethodServlet extends HttpServlet {
    //接收method=post的请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("doPost");
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write("doPost");
    }
    //接收method=put的请求
    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("doPut");
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write("doPut");
    }
    //接收method=delete的请求
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("doDelete");
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write("doDelete");
    }  
}

